/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.appleframework;

import org.appleframework.utils.IO;
import org.appleframework.vfs.FileSystem;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.appleframework.web.Router;


public class Apple {

  public static Mode mode; //运行模式
  public static Properties configuration; //配置文件
  public static String encode;
  public static File appPath; //项目路径
  public static FileSystem appRoot; //文件夹
  public static FileSystem appConfig; //配置文件
  public static FileSystem router; //路由配置
  public static FileSystem templatesPath; //模板

  //运行模式
  public enum Mode{
    DEV,PROD
  }

  //初始化
  public static void init(File root){
    Apple.appPath = root;
    appRoot = new FileSystem(appPath);
    start();
  }

  public static void start(){
    readConfiguration();

    mode = Mode.valueOf(configuration.getProperty("apple.mode", "DEV").toUpperCase());
    String level = configuration.getProperty("apple.log", "DEBUG").toUpperCase();
    Logger.setLevel(level);
    encode = configuration.getProperty("apple.encode","UTF-8").toUpperCase();
    router = appRoot.child("config/router");
    Router.load();
    templatesPath = appRoot.child("app/views");
  }

  public static void readConfiguration(){
    appConfig = appRoot.child("config/apple.conf");
    try {
      configuration = IO.readUtf8Properties(appConfig.inputstream());
    } catch (IOException ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }

  
}